{"componentChunkName":"component---node-modules-rocketseat-gatsby-theme-docs-core-src-templates-docs-query-js","path":"/manual-review/TickMath-TMH","result":{"data":{"mdx":{"id":"e38f6a36-d5f6-5d23-bc7b-7b60ad74f656","excerpt":"TMH-01M: Discrepancy of Whitepaper Formula 22 Type Severity Location Mathematical Operations TickMath.sol:L138-L148 Description: The implementation of  TickMath…","fields":{"slug":"/manual-review/TickMath-TMH/"},"frontmatter":{"title":"TickMath Manual Review Findings","description":"Contains all the findings that relate to manual review on the contract codebase","image":null,"disableTableOfContents":null},"body":"var _excluded = [\"components\"];\n\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"TickMath Manual Review Findings\",\n  \"description\": \"Contains all the findings that relate to manual review on the contract codebase\"\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h2\", {\n    \"id\": \"span-idtmh-01mtmh-01m-discrepancy-of-whitepaper-formula-22span\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#span-idtmh-01mtmh-01m-discrepancy-of-whitepaper-formula-22span\",\n    \"aria-label\": \"span idtmh 01mtmh 01m discrepancy of whitepaper formula 22span permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), mdx(\"span\", {\n    id: \"TMH-01M\"\n  }, \"TMH-01M: Discrepancy of Whitepaper Formula 22\")), mdx(\"table\", null, mdx(\"thead\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"thead\"\n  }, mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Type\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Severity\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Location\"))), mdx(\"tbody\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"a\", {\n    parentName: \"td\",\n    \"href\": \"/reports/maverick-protocol-common-libraries-66165d178c7ae500187a1ad7/appendix/finding-types#mathematical-operations\"\n  }, \"Mathematical Operations\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"img\", {\n    parentName: \"td\",\n    \"className\": \"o-severity o-unknown\",\n    \"src\": \"https://omniscia.io/report-assets/unknown.png\"\n  })), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"a\", {\n    parentName: \"td\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L138-L148\"\n  }, \"TickMath.sol:L138-L148\"))))), mdx(\"h3\", {\n    \"id\": \"description\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#description\",\n    \"aria-label\": \"description permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Description:\"), mdx(\"p\", null, \"The implementation of \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L83-L150\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"TickMath::getTickL\")), \" is meant to represent formula 22 of the whitepaper draft that calculates the aggregate liquidity of a tick based on the quadratic formula outlined in 21. The whitepaper deviates from the actual implementation of \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L83-L150\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"TickMath::getTickL\")), \" which implements:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-mermaid\"\n  }, \"math\\nL = \\\\frac{\\\\sqrt{p_u}}{\\\\sqrt{p_u} - \\\\sqrt{p_l}} (\\\\frac{b}{2} + \\\\sqrt{(\\\\frac{b}{2})^2 + \\\\frac{AB(\\\\sqrt{p_u} - \\\\sqrt{p_l})}{\\\\sqrt{p_u}}})\\n\")), mdx(\"p\", null, \"As can be observed, the formula implemented deviates from formula 22 as formula 22 will add the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"b / 2\"), \" factor instead of multiplying it.\"), mdx(\"h3\", {\n    \"id\": \"impact\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#impact\",\n    \"aria-label\": \"impact permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Impact:\"), mdx(\"p\", null, \"As the whitepaper is considered the source-of-truth in relation to the mathematical calculations of the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"TickMath\"), \" contract, we consider this exhibit to be of minor severity if the implemented formula by \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L83-L150\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"TickMath::getTickL\")), \" is correct.\"), mdx(\"p\", null, \"The severity of this exhibit will be revisited once either the implementation or the whitepaper are corrected.\"), mdx(\"h3\", {\n    \"id\": \"example\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#example\",\n    \"aria-label\": \"example permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Example:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-sol\",\n    \"metastring\": \"title=v2-common/contracts/libraries/TickMath.sol highlight={4,16,17,23,24} lineNumbers=true lineOffset=123\",\n    \"title\": \"v2-common/contracts/libraries/TickMath.sol\",\n    \"highlight\": \"{4,16,17,23,24}\",\n    \"lineNumbers\": \"true\",\n    \"lineOffset\": \"123\"\n  }, \"// need half b at this point\\n// b is in (7.2e-9 (2^57 / 1e7 / 2), 2.8e29  (2^(78+57) * 1e7 / 2)) with bump\\n// b is in a subset of the same range without bump\\nb >>= 1;\\n\\n// b^2 is in (5.1e-17, 4.8e58); and will not overflow on either end;\\n// A*B is in (3e-13 (2^78 / 1e18 * 1e-18), 1.9e45) without bump and is in a subset range with bump\\n// A*B*diff/sqrtUpper is in (1.5e-17 (3e-13 * 5e-12 * 1e7), 7.6e58);\\n\\n// Since b^2 is at the upper edge of the precision range, we are not\\n// able to multiply the argument of the sqrt by 1e18, instead, we move\\n// this factor outside of the sqrt. The resulting loss of precision\\n// means that this liquidity value is a lower bound on the tick\\n// liquidity\\nreturn\\n    OzMath.mulDiv(\\n        b +\\n            Math.sqrt(\\n                (OzMath.mulDiv(b, b, ONE) +\\n                    OzMath.mulDiv(reserveB.mulFloor(reserveA), diff, sqrtUpperTickPrice))\\n            ) *\\n            1e9,\\n        sqrtUpperTickPrice,\\n        diff\\n    ) >> precisionBump;\\n\")), mdx(\"h3\", {\n    \"id\": \"recommendation\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#recommendation\",\n    \"aria-label\": \"recommendation permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Recommendation:\"), mdx(\"p\", null, \"We evaluated the quadratic formula described in 21 and were unable to reproduce formula 22. Additionally, we were unable to properly correlate formula 21 to the formula implemented by \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L83-L150\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"TickMath::getTickL\")), \" and instead calculated significantly more complex fractions for the quadratic equation of 21.\"), mdx(\"p\", null, \"As the formula outlined in the whitepaper draft is incorrect, we advise it to be properly updated to reflect the latest implementation defined in \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L83-L150\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"TickMath::getTickL\")), \". Additionally, we advise a \", mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"step-by-step\"), \" solution of the quadratic formula to be performed as simplifications have occurred in between formula \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"21\"), \" and the implementation of \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L83-L150\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"TickMath::getTickL\")), \" that cannot be reliably deduced by performing the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"b\"), \" substitution as defined in the whitepaper.\"), mdx(\"h3\", {\n    \"id\": \"alleviation-175f8c39b19df69134add3aa8a2a042ce3047763\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#alleviation-175f8c39b19df69134add3aa8a2a042ce3047763\",\n    \"aria-label\": \"alleviation 175f8c39b19df69134add3aa8a2a042ce3047763 permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Alleviation (175f8c39b19df69134add3aa8a2a042ce3047763):\"), mdx(\"p\", null, \"The whitepaper draft has been updated to reflect the correct formula, addressing this exhibit as the whitepaper and code implementation are no longer desynchronized.\"), mdx(ViewDiffButton, {\n    repoUrl: \"https://github.com/maverickprotocol/maverick-v2\",\n    mainHash: \"47287a62e15ca8d4bcabf7e0b6757debb5d10593\",\n    fixHash: \"175f8c39b19df69134add3aa8a2a042ce3047763\",\n    gitHubIssue: \"0\",\n    mdxType: \"ViewDiffButton\"\n  }), mdx(\"h2\", {\n    \"id\": \"span-idtmh-02mtmh-02m-inexistent-accommodation-of-rounding-errorsspan\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#span-idtmh-02mtmh-02m-inexistent-accommodation-of-rounding-errorsspan\",\n    \"aria-label\": \"span idtmh 02mtmh 02m inexistent accommodation of rounding errorsspan permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), mdx(\"span\", {\n    id: \"TMH-02M\"\n  }, \"TMH-02M: Inexistent Accommodation of Rounding Errors\")), mdx(\"table\", null, mdx(\"thead\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"thead\"\n  }, mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Type\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Severity\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Location\"))), mdx(\"tbody\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"a\", {\n    parentName: \"td\",\n    \"href\": \"/reports/maverick-protocol-common-libraries-66165d178c7ae500187a1ad7/appendix/finding-types#mathematical-operations\"\n  }, \"Mathematical Operations\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"img\", {\n    parentName: \"td\",\n    \"className\": \"o-severity o-minor\",\n    \"src\": \"https://omniscia.io/report-assets/minor.png\"\n  })), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"a\", {\n    parentName: \"td\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L72\"\n  }, \"TickMath.sol:L72\"))))), mdx(\"h3\", {\n    \"id\": \"description-1\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#description-1\",\n    \"aria-label\": \"description 1 permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Description:\"), mdx(\"p\", null, \"The \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L18-L26\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"TickMath::tickSqrtPrice\")), \" function will not accommodate for rounding errors in contrast to its original Uniswap V3 counterpart, and rounding errors can occur for multiple \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"tick\"), \" values such as \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"319_487\"), \" which would be below the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Constants::MAX_TICK\"), \" limitation.\"), mdx(\"h3\", {\n    \"id\": \"impact-1\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#impact-1\",\n    \"aria-label\": \"impact 1 permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Impact:\"), mdx(\"p\", null, \"The precise ramifications of inexistent rounding are difficult to identify, and would effectively mean that the square root price would be lower by a single unit in certain circumstances.\"), mdx(\"p\", null, \"We do not consider the impact to be significant, however, we still consider it a flaw that should be remediated out of an abundance of caution.\"), mdx(\"h3\", {\n    \"id\": \"example-1\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#example-1\",\n    \"aria-label\": \"example 1 permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Example:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-sol\",\n    \"metastring\": \"title=v2-common/contracts/libraries/TickMath.sol highlight={31} lineNumbers=true lineOffset=41\",\n    \"title\": \"v2-common/contracts/libraries/TickMath.sol\",\n    \"highlight\": \"{31}\",\n    \"lineNumbers\": \"true\",\n    \"lineOffset\": \"41\"\n  }, \"/**\\n * @notice Calculate the square root price for a given tick and tick spacing.\\n * @param tickSpacing The tick spacing used for calculations.\\n * @param _tick The input tick value.\\n * @return _result The square root price.\\n */\\nfunction tickSqrtPrice(uint256 tickSpacing, int32 _tick) internal pure returns (uint256 _result) {\\n    unchecked {\\n        uint256 tick = subTickIndex(tickSpacing, _tick);\\n\\n        uint256 ratio = tick & 0x1 != 0 ? 0xfffcb933bd6fad9d3af5f0b9f25db4d6 : 0x100000000000000000000000000000000;\\n        if (tick & 0x2 != 0) ratio = (ratio * 0xfff97272373d41fd789c8cb37ffcaa1c) >> 128;\\n        if (tick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656ac9229c67059486f389) >> 128;\\n        if (tick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e81259b3cddc7a064941) >> 128;\\n        if (tick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f67b19e8887e0bd251eb7) >> 128;\\n        if (tick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98cd2e57b660be99eb2c4a) >> 128;\\n        if (tick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c9838804e327cb417cafcb) >> 128;\\n        if (tick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99d51e2cc356c2f617dbe0) >> 128;\\n        if (tick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900aecf64236ab31f1f9dcb5) >> 128;\\n        if (tick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac4d9194200696907cf2e37) >> 128;\\n        if (tick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b88206f8abe8a3b44dd9be) >> 128;\\n        if (tick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c578ef4f1d17b2b235d480) >> 128;\\n        if (tick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd254ee83bdd3f248e7e785e) >> 128;\\n        if (tick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d8f7dd10e744d913d033333) >> 128;\\n        if (tick & 0x4000 != 0) ratio = (ratio * 0x70d869a156ddd32a39e257bc3f50aa9b) >> 128;\\n        if (tick & 0x8000 != 0) ratio = (ratio * 0x31be135f97da6e09a19dc367e3b6da40) >> 128;\\n        if (tick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7e5a9780b0cc4e25d61a56) >> 128;\\n        if (tick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedbcb3a6ccb7ce618d14225) >> 128;\\n        if (tick & 0x40000 != 0) ratio = (ratio * 0x2216e584f630389b2052b8db590e) >> 128;\\n        if (_tick > 0) ratio = type(uint256).max / ratio;\\n        _result = (ratio * ONE) >> 128;\\n    }\\n}\\n\")), mdx(\"h3\", {\n    \"id\": \"recommendation-1\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#recommendation-1\",\n    \"aria-label\": \"recommendation 1 permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Recommendation:\"), mdx(\"p\", null, \"We advise outputs of the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/maverickprotocol/maverick-v2/blob/47287a62e15ca8d4bcabf7e0b6757debb5d10593/v2-common/contracts/libraries/TickMath.sol#L18-L26\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"TickMath::tickSqrtPrice\")), \" function to be made consistent by incorporating a rounding approach similar to Uniswap V3.\"), mdx(\"h3\", {\n    \"id\": \"alleviation-175f8c39b19df69134add3aa8a2a042ce3047763-1\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#alleviation-175f8c39b19df69134add3aa8a2a042ce3047763-1\",\n    \"aria-label\": \"alleviation 175f8c39b19df69134add3aa8a2a042ce3047763 1 permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Alleviation (175f8c39b19df69134add3aa8a2a042ce3047763):\"), mdx(\"p\", null, \"The Maverick Protocol team evaluated this exhibit, and clarified that a rounding operation is unnecessary in the case of the Maverick Protocol AMM.\"), mdx(\"p\", null, \"The Uniswap AMM needs to round upwards so as to be able to invert a price back to its tick via a logarithm operation.\"), mdx(\"p\", null, \"As the Maverick Protocol AMM does not need to conduct such an operation and merely needs consistency in the function's outputs, the current implementation is adequately secure rendering this exhibit inapplicable.\"));\n}\n;\nMDXContent.isMDXComponent = true;","headings":[{"depth":2,"value":"<span id=\"TMH-01M\">TMH-01M: Discrepancy of Whitepaper Formula 22</span>"},{"depth":3,"value":"Description:"},{"depth":3,"value":"Impact:"},{"depth":3,"value":"Example:"},{"depth":3,"value":"Recommendation:"},{"depth":3,"value":"Alleviation (175f8c39b19df69134add3aa8a2a042ce3047763):"},{"depth":2,"value":"<span id=\"TMH-02M\">TMH-02M: Inexistent Accommodation of Rounding Errors</span>"},{"depth":3,"value":"Description:"},{"depth":3,"value":"Impact:"},{"depth":3,"value":"Example:"},{"depth":3,"value":"Recommendation:"},{"depth":3,"value":"Alleviation (175f8c39b19df69134add3aa8a2a042ce3047763):"}]}},"pageContext":{"slug":"/manual-review/TickMath-TMH/","prev":{"label":"Math.sol (MHT-M)","link":"/manual-review/Math-MHT"},"next":{"label":"TransferLib.sol (TLB-M)","link":"/manual-review/TransferLib-TLB"}}},"staticQueryHashes":["1954253342","2328931024","2501019404","973074209"]}